const db = wx.cloud.database()
var util = require('../../utils/util.js')
Page({
  data: {
    newslist: {},
  },

  onLoad: function (options) {
    db.collection('news').orderBy('istop', 'desc').orderBy('submitdate', 'desc').get().then(res => {
        for (var index in res.data) {
          res.data[index].time = util.formatTime(res.data[index].submitdate)
        }
        this.setData({newslist: res.data})
      })
      .catch(err => {
        console.error(err)
      })
  },

  onShow: function () {
    this.onLoad()
  },

  newsClick: function (event) {
    wx.cloud.callFunction({
      name: 'news',
      data: {
        $url: "view_inc", // 要调用的路由的路径，传入准确路径或者通配符*
        id: event.currentTarget.dataset.id
      },
      success: res => {
        //console.log(res)
      }
    })
    wx.navigateTo({
      url: '../newsdetail/newsdetail?id=' + event.currentTarget.dataset.id
    })
  },
})